package 剑指offer_leetcode;

/**
 * JZ44数字序列中某一位的数字
 */
public class 剑指Offer44_数字序列中某一位的数字 {
    public int findNthDigit(int n) {
        int digit = 1;
        long start = 1;
        long sum = 9;
        while(n>sum){
            digit++;
            start *= 10;
            n-=sum;
            sum = 9 * start * digit;
        }
        String num = "" + (start + (n-1)/digit);
        int index = (n-1) % digit;
        return num.charAt(index) - '0';
    }
}
